﻿using CheatMenu.Managers;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;
using CheatMenu.Utils;
using BepInEx.Logging;
using Logger = BepInEx.Logger;
using CheatMenu.Patch;

namespace CheatMenu.Menus
{
    public class MenuCommands : MenuButtonList
    {
        public MenuCommands() : base("Commands", null)
        {
            Alignment = Alignment.BottomRight;

            CommandGroup groupState = new CommandGroup("Gamestate");
            groupState.AddCommand("+$100", (c) => StateManager.AddInt("money", 100));
            groupState.AddCommand("Full Energy", (c) => StateManager.SetInt("energ", StateManager.GetInt("total_energ")));
            groupState.AddCommand("Time-1", (c) => StateManager.AddInt("time", -1));
            groupState.AddCommand("Time+1", (c) => StateManager.AddInt("time", 1));
            CommandGroups.Add(groupState);

            CommandGroup groupInventory = new CommandGroup("Inventory");
            groupInventory.AddCommand("Full Lube", (c) => StateManager.SetInt("lube", 3));
            groupInventory.AddCommand("Full Condoms", (c) => StateManager.SetInt("condoms", 3));
            groupInventory.AddCommand("Full Suncream", (c) => StateManager.SetInt("suncream", 3));
            groupInventory.AddCommand("Full VitaminX", (c) => StateManager.SetInt("drugs", 20));
            groupInventory.AddCommand("Full PlanB", (c) => StateManager.SetInt("mpills", 20));
            groupInventory.AddCommand("Full Sleeping", (c) => StateManager.SetInt("spills", 20));
            groupInventory.AddCommand("Full Lactation", (c) => StateManager.SetInt("lpills", 20));
            CommandGroups.Add(groupInventory);

            CommandGroup groupAdvanced = new CommandGroup("Advanced");
            groupAdvanced.AddCommand("LoadScene", (c) => MenuManager.GetMenu<MenuLoadScene>().ToggleShown());
            groupAdvanced.AddCommand("RandomInteger", (c) => 
            {
                c.ToggleState = RandomIntegerPatcher.Enabled = !RandomIntegerPatcher.Enabled;
            }, RandomIntegerPatcher.Enabled);
            groupAdvanced.AddCommand("InstantText", (c) => 
            {
                c.ToggleState = InstantTextPatcher.Enabled = GUIManager.InstantText = !GUIManager.InstantText;
            }, GUIManager.InstantText);
            groupAdvanced.AddCommand("RunInBackground", (c) =>
            {
                c.ToggleState = Application.runInBackground = GUIManager.RunInBackground = !GUIManager.RunInBackground;
            }, GUIManager.RunInBackground);
            //groupAdvanced.AddCommand("ExecBlock", () => promptExecBlockScene.ToggleShown());
            CommandGroups.Add(groupAdvanced);
        }

        protected override void OnHidden() => MenuManager.GetMenu<MenuLoadScene>().Shown = false;

        protected override Vector2 InitializeSize()
        => new Vector2((GUIManager.ControlHeight * 8f) + (GUIManager.PaddingSize * 2) + GUIManager.ScrollBarWidth, (GUIManager.ControlHeight * 12) + (GUIManager.PaddingSize * 2));
    }
}
